package com.linbei.linbei_movie.service.impl;

import com.linbei.linbei_movie.mapper.MovieMapper;
import com.linbei.linbei_movie.pojo.Movie;
import com.linbei.linbei_movie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MovieServiceImpl implements MovieService {

    @Autowired
    private MovieMapper movieMapper;

    @Override
    public List<Movie> getAllMovies() {
        return movieMapper.getAllMovies();
    }

    @Override
    public Movie getMovieById(Long movieId) {
        return movieMapper.getMovieById(movieId);
    }

    @Override
    public Movie createMovie(Movie movie) {
        movieMapper.createMovie(movie);
        return movie;
    }

    @Override
    public Movie updateMovie(Long movieId, Movie movie) {
        movie.setMovieId(movieId);
        int rowsAffected = movieMapper.updateMovie(movie);
        return rowsAffected > 0 ? movie : null;
    }

    @Override
    public boolean deleteMovie(Long movieId) {
        int rowsAffected = movieMapper.deleteMovie(movieId);
        return rowsAffected > 0;
    }
}